package jxls;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import net.sf.jxls.exception.ParsePropertyException;
import net.sf.jxls.transformer.XLSTransformer;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;

public class MergeTest {

	public static void main(String[] args) throws ParsePropertyException, InvalidFormatException, IOException {

		String rootPath = System.getProperty("user.dir");
		String template = rootPath + "/template/mergeTest.xls";  
		String generate = rootPath + "/generate/mergeTest.xls";  
  
		Map<String, Object> beanParams = new HashMap<String, Object>();
		ArrayList<Integer> list = new ArrayList<Integer>();
		list.add(4);
		list.add(6);
		list.add(7);
		list.add(0);
        beanParams.put("list", list);
        
        XLSTransformer former = new XLSTransformer();
        
        InputStream in = new FileInputStream(template);
        OutputStream out = new FileOutputStream(generate);
        Workbook wb = former.transformXLS(in, beanParams);
        
        CellRangeAddress merge = new CellRangeAddress(0, 5, 0 , 0);
        wb.getSheetAt(0).addMergedRegion(merge);
        wb.write(out);
        
        in.close();
        out.close();
	}

}
